package jjn.acwing.algorithm_basic.chapter1.range;

import java.io.IOException;
import java.util.*;

/**
 * @author Jiang Jining
 * @since 2023-09-25 22:51
 */
public class Acwing803 {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] nums = new int[n][2];
        for (int i = 0; i < n; i++) {
            nums[i][0] = scanner.nextInt();
            nums[i][1] = scanner.nextInt();
        }
        Arrays.sort(nums, Comparator.comparingInt(i -> i[0]));
        Deque<int[]> deque = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            int[] num = nums[i];
            if (deque.isEmpty() || deque.peekLast()[1] < num[0]) {
                deque.offer(num);
            } else {
                int[] last = deque.peekLast();
                if (last[1] < num[1]) {
                    last[1] = num[1];
                }
            }
        }
        System.out.println(deque.size());
    }
}
